home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc International / Development / TSMTEsample⁄1.1 / Source / TempFocus.cpp < prev    next >
Encoding:
Text File  |  1996-11-14  |  4.1 KB  |  170 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TempFocus.cpp
  3.  
  4.     Contains:    Stack-based utility classes for requesting and releasing foci.
  5.  
  6.     Written by:    Troy Gaul
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- Compiler/Preprocessor Switches --
  12.  
  13. #ifndef _COMPILERDEFS_
  14. #include "CompDefs.h"
  15. #endif
  16.  
  17. // -- OpenDoc Utilities --
  18.  
  19. #ifndef _EXCEPT_
  20. // Exceptions define several important macros (eg. CHECKENV)
  21. // which are used in the SOM method dispatch glue. If Except.h
  22. // is not included early enough, exceptions may not be thrown
  23. // correctly when returning from a SOM method with the "ev" parameter set.
  24. #include <Except.h>
  25. #endif
  26.  
  27. // -- Utility Includes --
  28.  
  29. #ifndef _TEMPFOCUS_
  30. #include "TempFocus.h"
  31. #endif
  32.  
  33. // -- OpenDoc Includes --
  34.  
  35. #ifndef SOM_ODArbitrator_xh
  36. #include <Arbitrat.xh>
  37. #endif
  38.  
  39. #ifndef SOM_Module_OpenDoc_Foci_defined
  40. #include <Foci.xh>
  41. #endif
  42.  
  43. #ifndef SOM_ODFrame_xh
  44. #include <Frame.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODSession_xh
  48. #include <ODSessn.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODPart_xh
  52. #include <Part.xh>
  53. #endif
  54.  
  55. // -- OpenDoc Utilities --
  56.  
  57. #ifndef _ODDEBUG_
  58. #include <ODDebug.h>
  59. #endif
  60.  
  61. #ifndef _ODUTILS_
  62. #include <ODUtils.h>
  63. #endif
  64.  
  65. #ifndef _TEMPOBJ_
  66. #include <TempObj.h>
  67. #endif
  68.  
  69.  
  70. #pragma segment TempFocus
  71.  
  72.  
  73. //=========================================================================
  74. // Utilities
  75. //=========================================================================
  76.  
  77. //-------------------------------------------------------------------------
  78. // ::GetSessionFromFrame
  79. //-------------------------------------------------------------------------
  80. static ODSession*
  81. GetSessionFromFrame(Environment* ev, ODFrame* frame)
  82. {
  83.     TempODPart part = frame->AcquirePart(ev);
  84.     return ODGetSession(ev, part);    
  85. }
  86.  
  87. //=========================================================================
  88. // TempFocus
  89. //=========================================================================
  90.  
  91. //-------------------------------------------------------------------------
  92. // TempFocus::TempFocus
  93. //-------------------------------------------------------------------------
  94.  
  95. TempFocus::TempFocus( Environment*        ev, 
  96.                       ODTypeToken        focusType, 
  97.                       ODFrame*            frame )
  98. {
  99.     fEv = ev;
  100.     fFrameToFocus = frame;
  101.     fAcquired = kODFalse;
  102.     fFocusType = focusType;
  103. }
  104.     
  105. //-------------------------------------------------------------------------
  106. // TempFocus::TempFocus
  107. //-------------------------------------------------------------------------
  108.  
  109. TempFocus::TempFocus( Environment*        ev, 
  110.                       ODFrame*            frame )
  111. {
  112.     fEv = ev;
  113.     fFrameToFocus = frame;
  114.     fAcquired = kODFalse;
  115.     fFocusType = kODNullTypeToken;
  116. }
  117.     
  118. //-------------------------------------------------------------------------
  119. // TempFocus::~TempFocus
  120. //-------------------------------------------------------------------------
  121.  
  122. TempFocus::~TempFocus()
  123. {
  124.     if (fAcquired)
  125.     {
  126.         // Relinquish the clipboard focus
  127.         GetSessionFromFrame(fEv, fFrameToFocus)->GetArbitrator(fEv)
  128.                 ->RelinquishFocus(fEv, fFocusType, fFrameToFocus);
  129.     }
  130. }
  131.  
  132. //-------------------------------------------------------------------------
  133. // TempFocus::Request
  134. //-------------------------------------------------------------------------
  135.  
  136. ODBoolean TempFocus::Request()
  137. {
  138.     WASSERT(fFocusType != kODNullTypeToken);
  139.  
  140.     ODArbitrator* arbitrator = GetSessionFromFrame(fEv, fFrameToFocus)->GetArbitrator(fEv);
  141.     
  142.     TempODFrame focusedFrame = arbitrator->AcquireFocusOwner(fEv, fFocusType);
  143.     
  144.     fAcquired = ( fAcquired
  145.                || ODObjectsAreEqual(fEv, fFrameToFocus, focusedFrame)
  146.                || arbitrator->RequestFocus(fEv, fFocusType, fFrameToFocus) );
  147.  
  148.     return fAcquired;
  149. }
  150.  
  151. //=========================================================================
  152. // TempClipboardFocus
  153. //=========================================================================
  154.  
  155. ODTypeToken sClipboardToken = kODNullTypeToken;
  156.  
  157. //-------------------------------------------------------------------------
  158. // TempClipboardFocus::TempClipboardFocus
  159. //-------------------------------------------------------------------------
  160.  
  161. TempClipboardFocus::TempClipboardFocus( Environment* ev, ODFrame* frame )
  162.     : TempFocus(ev, frame)
  163. {
  164.     if ( sClipboardToken == kODNullTypeToken )
  165.         sClipboardToken = GetSessionFromFrame(ev, frame)->Tokenize(ev, kODClipboardFocus);
  166.     
  167.     fFocusType = sClipboardToken;
  168. }
  169.  
  170.